package canss.webservice.servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import canss.supports.basic;
import canss.webservice.model.Person;
import canss.webservice.service.PortalIntraWebServiceControl;
import canss.webservice.service.PortalIntraWebServiceControlBean;

public class svtOPAdminPerson extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet
{
	private static final long serialVersionUID = -3723228141341557915L;

	public svtOPAdminPerson()
	{
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doPost(request, response);
	}

	PortalIntraWebServiceControl control;
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		response.setContentType("text/html; charset=UTF-8");

		PrintWriter out = response.getWriter();

		String _notxml = request.getParameter("_notxml");

		control = (control == null) ? new PortalIntraWebServiceControlBean() : control;

		if (_notxml != null)
		{// in html
		} else
		{// in xml
			out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
			weblogic.application.utils.XMLWriter writer = new weblogic.application.utils.XMLWriter(out);

			writer.addElement("canss");
			{
				Person[] persons = control.getEntirePerson();
				if(persons!=null)
				{
					for(Person person : persons)
					{
						writer.addElement("canssPerson_Person");
							writer.addElement("canssPerson_id", person.getTBLPID_PID().trim());
							writer.addElement("canssPerson_name", person.getCANSSPERSON_NAME().trim());
							writer.addElement("canssPerson_type", basic.PERSONTYPEINTOSTR(person.getCANSSPERSON_TYPE()).trim());
							writer.addElement("canssPerson_local_entrydate", person.getLOCAL_ENTRYDATESTR().trim());
							writer.addElement("canssPerson_typeatt_key", person.getCANSSPERSON_TYPEATT_KEY());
							
							String js_p_inform = "var frm=getobj('frm_personlist_{$v_pid}');if(frm){window.open('','pop_personinform','width=740,height=850');frm.action='getPersonInform.jsp';frm.method='get';frm.target='pop_personinform';frm.submit();}";
							String js_p_key_add = "";
							String js_p_key_rm = "";
							if(person.getCANSSPERSON_TYPE()/10 == basic.DEFAULT_PERSONTYPE_THIRDPARTY/10)
							{
								js_p_key_add = "var frm=getobj('frm_personlist_{$v_pid}');if(frm){frm.target='';frm.action='svtAjaxGetKey';frm.method='post';frm.submit();}"; 
								js_p_key_rm = "var frm=getobj('frm_personlist_{$v_pid}');if(frm){frm.target='';frm.action='svtAjaxGetKey';frm.method='post';frm.submit();}";
							}
							writer.addElement("js_p_inform", js_p_inform.replace("{$v_pid}", person.getTBLPID_PID().trim()));
							writer.addElement("js_p_key_add", js_p_key_add.replace("{$v_pid}", person.getTBLPID_PID().trim()));
							writer.addElement("js_p_key_rm", js_p_key_rm.replace("{$v_pid}", person.getTBLPID_PID().trim()));
						writer.closeElement();
					}
				}
			}
			writer.finish();
		}
	}
}